

class CallDetailController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        [ callDetailInstanceList: CallDetail.list( params ), callDetailInstanceTotal: CallDetail.count() ]
    }

    def myList = {
        //params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        def l = CallDetail.findAllByUser( session.user )
        def p = [ callDetailInstanceList: l, callDetailInstanceTotal: l.count() ]
        render(view:"list", model:p)
    }

    def show = {
        def callDetailInstance = CallDetail.get( params.id )

        if(!callDetailInstance) {
            flash.message = "CallDetail not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ callDetailInstance : callDetailInstance ] }
    }

    def delete = {
        def callDetailInstance = CallDetail.get( params.id )
        if(callDetailInstance) {
            try {
                callDetailInstance.delete(flush:true)
                flash.message = "CallDetail ${params.id} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "CallDetail ${params.id} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "CallDetail not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def callDetailInstance = CallDetail.get( params.id )

        if(!callDetailInstance) {
            flash.message = "CallDetail not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ callDetailInstance : callDetailInstance ]
        }
    }

    def update = {
        def callDetailInstance = CallDetail.get( params.id )
        if(callDetailInstance) {
            if(params.version) {
                def version = params.version.toLong()
                if(callDetailInstance.version > version) {
                    
                    callDetailInstance.errors.rejectValue("version", "callDetail.optimistic.locking.failure", "Another user has updated this CallDetail while you were editing.")
                    render(view:'edit',model:[callDetailInstance:callDetailInstance])
                    return
                }
            }
            callDetailInstance.properties = params
            if(!callDetailInstance.hasErrors() && callDetailInstance.save()) {
                flash.message = "CallDetail ${params.id} updated"
                redirect(action:show,id:callDetailInstance.id)
            }
            else {
                render(view:'edit',model:[callDetailInstance:callDetailInstance])
            }
        }
        else {
            flash.message = "CallDetail not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def create = {
        def callDetailInstance = new CallDetail()
        callDetailInstance.properties = params
        return ['callDetailInstance':callDetailInstance]
    }

    def save = {
        def callDetailInstance = new CallDetail(params)
        if(!callDetailInstance.hasErrors() && callDetailInstance.save()) {
            flash.message = "CallDetail ${callDetailInstance.id} created"
            redirect(action:show,id:callDetailInstance.id)
        }
        else {
            render(view:'create',model:[callDetailInstance:callDetailInstance])
        }
    }
}
